package com.example.testservice;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.id_btn_startService).setOnClickListener(this);
        findViewById(R.id.id_btn_destoryService).setOnClickListener(this);
        findViewById(R.id.id_btn_bindservice).setOnClickListener(this);
        findViewById(R.id.id_btn_unbind).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.id_btn_startService:
                startService(new Intent(getBaseContext(), MyService.class)); // onCreate onStartCommand onStart called
                break;
            case R.id.id_btn_destoryService:
                stopService(new Intent(getBaseContext(), MyService.class)); // onDestroy called
                break;
            case R.id.id_btn_bindservice: //bind use method is not same with startService
//                stopService(new Intent(getBaseContext(), MyService.class)); // onDestroy called
                //public abstract boolean bindService(@RequiresPermission Intent service,
                //            @NonNull ServiceConnection conn, @BindServiceFlags int flags);
                //bindService()
                break;
            case R.id.id_btn_unbind:
                stopService(new Intent(getBaseContext(), MyService.class)); // onDestroy called
                break;
        }
    }
}
